package com.tm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tm.dto.SetmealDTO;
import com.tm.entity.SetmealEntity;
import com.tm.mapper.SetmealMapper;
import com.tm.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author huangp
 * @create 2023-04-06 15:57
 */
@Service
public class SetmealServiceImpl extends ServiceImpl<SetmealMapper, SetmealEntity> implements SetmealService {

    @Autowired
    private  SetmealMapper setmealMapper;

    @Override
    public Page<SetmealEntity> pageList(Integer page, Integer pageSize, SetmealDTO setmealDTO) {
       Page<SetmealEntity> page2 = new Page<>(page,pageSize);
        QueryWrapper<SetmealEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("a.is_deleted",0);
        queryWrapper.eq("c.type",2);
        queryWrapper.like(StringUtils.isNotBlank(setmealDTO.getName()),"a.name",setmealDTO.getName());
        Page<SetmealEntity> page6 =setmealMapper.pageList(page2,queryWrapper);
        return page6;
    }

    @Override
    public Boolean addSetmeal(SetmealEntity setmealEntity) {
        return setmealMapper.insert(setmealEntity) > 0;
    }


}
